package com.tanxi521.tnlevel.dao;


/**
 * @Author: i-xiaotian
 * @Date: 2022/3/13 5:34
 * @EMAIL: 1254806967@qq.com
 */
public enum SQLStatement {

    CREATE_TABLE_MYSQL("create table if not exists tn_level(" +
            "id int not null primary key auto_increment," +
            "player_uuid varchar(36) not null," +
            "display_name varchar(36) not null," +
            "player_level int not null," +
            "player_exp bigint not null," +
            "player_exp_to_next_level bigint not null," +
            "player_total_exp bigint not null," +
            "gmt_create bigint not null," +
            "gmt_update bigint not null);"),

    CREATE_TABLE_SQLITE(CREATE_TABLE_MYSQL.getStatement().replace("auto_increment", "autoincrement")
            .replace(" bigint ", " integer ").replace(" int ", " integer ")),

    SELECT_PLAYER("select id," +
            "player_uuid," +
            "display_name," +
            "player_level," +
            "player_exp," +
            "player_exp_to_next_level," +
            "player_total_exp," +
            "gmt_create," +
            "gmt_update " +
            "from tn_level where display_name = ?"),

    SELECT_PLAYER_BY_UUID("select id," +
            "player_uuid," +
            "display_name," +
            "player_level," +
            "player_exp," +
            "player_exp_to_next_level," +
            "player_total_exp," +
            "gmt_create," +
            "gmt_update " +
            "from tn_level where player_uuid = ?"),

    UPDATE_PLAYER("update tn_level set " +
            "player_level=?," +
            "player_exp=?," +
            "player_exp_to_next_level=?," +
            "player_total_exp=?," +
            "gmt_update=? " +
            "where display_name=?"),

    INSERT_ONE("insert into tn_level(" +
            "player_uuid," +
            "display_name," +
            "player_level," +
            "player_exp," +
            "player_exp_to_next_level," +
            "player_total_exp," +
            "gmt_create," +
            "gmt_update) " +
            "select ?,?,?,?,?,?,?,? " +
            "from dual where not exists (" +
            "select display_name from tn_level " +
            "where display_name=?);"),
    INSERT_TWO("insert into tn_level(" +
            "player_uuid," +
            "display_name," +
            "player_level," +
            "player_exp," +
            "player_exp_to_next_level," +
            "player_total_exp," +
            "gmt_create," +
            "gmt_update) " +
            "select ?,?,?,?,?,?,?,? " +
            "where not exists (" +
            "select display_name from tn_level " +
            "where display_name=?);"),
    SELECT_COUNT("select count(0) from tn_level"),
    SELECT_TOP("select id," +
            "player_uuid," +
            "display_name," +
            "player_level," +
            "player_exp," +
            "player_exp_to_next_level," +
            "player_total_exp," +
            "gmt_create," +
            "gmt_update " +
            "from tn_level order by player_total_exp desc limit ?, ?"),

    CHECK_CONNECTION("SELECT 1"),
    ;

    private final String statement;

    SQLStatement(String statement) {
        this.statement = statement;
    }

    public String getStatement() {
        return statement;
    }
}
